<?php

namespace App\Repository\Repositories;


use App\Helpers\Image;
use App\Models\StoreBargain;
use App\Models\StoreProduct;
use App\Models\StoreProductAttr;

use App\Repository\RepositoryInterface\BargainInterface;

class BargainRepositories implements BargainInterface
{
    /**
     * 砍价商品
     * @return StoreBargain[]|\Illuminate\Database\Eloquent\Collection
     */
    public function selAll()
    {
        return StoreBargain::with('StoreProduct')->paginate(5);
    }

    /**
     * 砍价列表
     * @return mixed
     */
    public function selList()
    {
        return StoreBargain::paginate(5);
    }

    /**
     * 修改状态
     * @param $id  主键id
     * @param $status  状态
     * @return mixed
     */
    public function upSatatu($id, $status)
    {
       if($status == 0) {
           return StoreBargain::where('id',$id)->update(['status'=>1]);
       }
        return StoreBargain::where('id',$id)->update(['status'=>0]);
    }

    /**
     * @param $id 主键id
     * @return mixed  删除
     */
    public function bargainDel($id)
    {
        return StoreBargain::where('id',$id)->delete();
    }

    /**
     * @param $data  数据
     * @return mixed   添加
     */
    public function bargainCreate($data)
    {
        return StoreBargain::create($data);
    }

    /**
     * @param $id  主键id
     * @return mixed  查询数据
     */
    public function bargainDetail($id)
    {
        return StoreBargain::where('id',$id)->first();
    }

    /**
     * @param $data  数据
     * @return mixed 修改
     */
    public function bargainUpdate($id,$data)
    {
        return StoreBargain::where('id',$id)->update($data);
    }

    /**
     * @param $bargainStatus
     * @param $id  搜索
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function searchData($bargainStatus,$id)
    {
        $where = [];
        if (!empty($bargainStatus)){
            $where[] = [
                'status','=',"$bargainStatus"
            ];
        }
        if (!empty($id)){
            $where[] = [
                'id','=',"$id"
            ];
        }
        return StoreBargain::with('StoreProduct')
            ->where($where)->paginate(5);
    }
    /**
     * @param $bargainStatus
     * @param $id  搜索
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function searchListData($status,$date)
    {
        $where = [];
        if (!empty($status)){
            $where[] = [
                'status','=',$status
            ];
        }
        if (!empty($date)){
            $where[] = [
                'stop_time','=',$date
            ];
        }
        return StoreBargain::with('StoreProduct')
            ->where($where)->paginate(5);
    }

    /**
     * @return mixed  商品列表
     */
    public function shopList($page)
    {
//        return StoreProduct::paginate(10);
        return StoreProduct::query($page)->paginate(5);

    }
    /**
     * @return mixed  商品属性
     */
    public function getSku($id)
    {
        return StoreProductAttr::where('Product_id',$id)->get();
    }

    

}
